package net.linku.constant;

/**
 * 登录的常量
 */
public class LoginConstant {

    /**
     * 后台管理人员
     */
    public static final String ADMIN_TYPE = "admin_type";

    /**
     * 普通的用户
     */
    public static final String MEMBER_TYPE = "member_type";

    /**
     * app的用户
     */
    public static final String PORTAL_TYPE = "portal_type";

    /**
     * 使用用户名查询用户
     */
    public static final String QUERY_ADMIN_SQL =
            "SELECT laa.id, laa.account_code, laa.`password`, laa.enabled_flag FROM `l_a_account` laa  WHERE laa.deleted_flag = 0 AND laa.account_code = ? AND laa.tenant_id = ?";

    /**
     * 查询用户的角色Code及其父角色Code
     */
    public static final String QUERY_ROLE_CODE_SQL =
            "SELECT  parent_lar.`code` AS parent_role_code " +
                    "FROM l_a_role lar " +
                    "LEFT JOIN l_a_account_role laar ON laar.role_id = lar.id AND laar.deleted_flag = 0 " +
                    "LEFT JOIN l_a_role parent_lar ON lar.parent_id = parent_lar.id " +
                    "WHERE lar.deleted_flag = 0 AND laar.account_id = ? AND lar.tenant_id = ?";


    /**
     * 查询所有的权限名称
     */
    public static final String QUERY_ALL_PERMISSIONS =
            "SELECT lap.`name` FROM `l_a_privilege` lap WHERE lap.tenant_id = ?";

    /**
     * 对于非超级用户，查询角色关联的权限名称
     */
    public static final String QUERY_PERMISSION_SQL =
            "SELECT lap.`name` " +
                    "FROM l_a_privilege lap " +
                    "LEFT JOIN l_a_role_privilege larp ON lap.id = larp.privilege_id AND larp.deleted_flag = 0 " +
                    "LEFT JOIN l_a_account_role laar ON larp.role_id = laar.role_id AND laar.deleted_flag = 0 " +
                    "WHERE lap.deleted_flag = 0 AND laar.account_id = ? AND lap.tenant_id = ?";

    /**
     * 超级管理员的角色的Code
     */
    public static final String ADMIN_ROLE_CODE = "ROLE_ADMIN";

    /**
     * 会员查询SQL
     */
    public static final String QUERY_MEMBER_SQL =
            "SELECT `id`,`password`, `status` FROM `user` WHERE (mobile = ? or email = ?) AND tenant_id = ?";

    /**
     * 前台用户查询SQL
     */
    public static final String QUERY_PORTAL_SQL =
            "SELECT\n" +
                    "\tlpa.id,\n" +
                    "\tlpa.account_code,\n" +
                    "\tlpa.PASSWORD,\n" +
                    "\tlpa.enabled_flag \n" +
                    "FROM\n" +
                    "\t`l_p_account` lpa \n" +
                    "WHERE\n" +
                    "\tlpa.deleted_flag = 0 \n" +
                    "\tAND lpa.enabled_flag = 1 \n" +
                    "\tAND (\n" +
                    "\tlpa.phone = ? \n" +
                    "\tOR lpa.account_code = ?)\n" +
                    "\tAND lpa.tenant_id = ?";

    public static final String REFRESH_TYPE = "REFRESH_TOKEN";


    /**
     * 使用后台用户的id 查询用户名称
     */
    public static final String QUERY_ADMIN_USER_WITH_ID = "SELECT laa.account_code FROM l_a_account laa WHERE laa.deleted_flag = 0 AND laa.id = ? AND laa.tenant_id = ?";

    /**
     * 使用用户的id 查询用户名称
     */
    public static final String QUERY_MEMBER_USER_WITH_ID = "SELECT `mobile` FROM user where id = ? AND tenant_id = ?";

    /**
     * 使用用户的id 查询用户名称
     */
    public static final String QUERY_PORTAL_USER_WITH_ID = "select lpa.phone from l_p_account lpa where lpa.deleted_flag = 0 AND lpa.id = ? AND lpa.tenant_id = ?";
}
